{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 对活动进行聚类\n",
    "\n",
    "数据来源于Kaggle竞赛：Event Recommendation Engine Challenge，根据\n",
    "events they’ve responded to in the past\n",
    "user demographic information\n",
    "what events they’ve seen and clicked on in our app\n",
    "用户对某个事件是否感兴趣\n",
    "\n",
    "竞赛官网：\n",
    "https://www.kaggle.com/c/event-recommendation-engine-challenge/data\n",
    "\n",
    "活动描述信息在events.csv文件：共110维特征\n",
    "前9列：event_id, user_id, start_time, city, state, zip, country, lat, and lng.\n",
    "event_id：活动的id, \n",
    "user_id：创建活动的用户的id .  \n",
    "city, state, zip, and country： 活动地点 (如果知道的话).\n",
    "lat and lng： floats（活动地点的经度和纬度）\n",
    "start_time： 字符串，ISO-8601 UTC time，表示活动开始时间\n",
    "\n",
    "后101列为词频：count_1, count_2, ..., count_100，count_other\n",
    "count_N：活动描述出现第N个词的次数\n",
    "count_other：除了最常用的100个词之外的其余词出现的次数\n",
    "\n",
    "作业要求：\n",
    "根据活动的关键词（count_1, count_2, ..., count_100，count_other属性）做聚类，可采用KMeans聚类\n",
    "尝试K=10，20，30，..., 100, 并计算各自CH_scores。\n",
    "\n",
    "提示：由于样本数目较多，建议使用MiniBatchKMeans。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "## 导入工具包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "from sklearn import metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#读取数据\n",
    "import scipy.io as sio\n",
    "eventContMatrix = sio.mmread(\"EV_eventContMatrix\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import MiniBatchKMeans\n",
    "\n",
    "# 一个参数点（聚类数据为K）的模型，并评价聚类算法性能\n",
    "def K_cluster_analysis(K, df):\n",
    "    print(\"K-means begin with clusters: {}\".format(K));\n",
    "    \n",
    "    #K-means,在训练集上训练\n",
    "    km = MiniBatchKMeans(n_clusters = K)\n",
    "    km.fit(df)\n",
    "    \n",
    "    #保存预测结果\n",
    "    cluster_result = km.predict(df)\n",
    "\n",
    "    # K值的评估标准\n",
    "    #常见的方法有轮廓系数Silhouette Coefficient和Calinski-Harabasz Index\n",
    "    #这两个分数值越大则聚类效果越好\n",
    "    #CH_score = metrics.calinski_harabaz_score(X_train,mb_kmeans.predict(X_train))\n",
    "    CH_score = metrics.silhouette_score(df,cluster_result)   \n",
    "    print(\"CH_score: {}\".format(CH_score))\n",
    "\n",
    "    return CH_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "K-means begin with clusters: 10\n",
      "CH_score: 0.129617000769\n",
      "K-means begin with clusters: 20\n",
      "CH_score: 0.151299662488\n",
      "K-means begin with clusters: 30\n",
      "CH_score: 0.140297553334\n",
      "K-means begin with clusters: 40\n",
      "CH_score: 0.142668713971\n",
      "K-means begin with clusters: 50\n",
      "CH_score: 0.150024461162\n",
      "K-means begin with clusters: 60\n",
      "CH_score: 0.14222995009\n",
      "K-means begin with clusters: 70\n",
      "CH_score: 0.147790660587\n",
      "K-means begin with clusters: 80\n",
      "CH_score: 0.138023144758\n",
      "K-means begin with clusters: 90\n",
      "CH_score: 0.146319218488\n",
      "K-means begin with clusters: 100\n",
      "CH_score: 0.121895327324\n"
     ]
    }
   ],
   "source": [
    "# 设置超参数（聚类数目K）搜索范围\n",
    "CH_scores = []\n",
    "Ks = [10,20,30,40,50,60,70,80,90,100]\n",
    "for K in Ks:\n",
    "    ch = K_cluster_analysis(K, eventContMatrix)\n",
    "    CH_scores.append(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.12961700076854937, 0.15129966248818469, 0.14029755333403887, 0.14266871397144812, 0.15002446116240514, 0.14222995008987604, 0.147790660587202, 0.13802314475815275, 0.14631921848849411, 0.12189532732374418]\n"
     ]
    }
   ],
   "source": [
    "print CH_scores"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x10e16b190>]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3XmcU+XZ8PHfxSaKomwqArIoKiiK\nkCjg8vjo+7gr1qp1q4IiaqVWEBQfRQV9rNQNFPB1rdK6trZKXWur+DhxY4ZVUGBQlgEFXBAEBYa5\n3j+u5CUMM0xmJsk5Sa7v55PPTE5OzrmTyeQ693bdoqo455xzDYIugHPOuXDwgOCccw7wgOCccy7O\nA4JzzjnAA4Jzzrk4DwjOOecADwjOOefiPCA455wDPCA455yLaxR0AWqjdevW2qlTp6CL4ZxzOaWk\npOQbVW1T0345FRA6depEcXFx0MVwzrmcIiJLUtnPm4ycc84BHhCcc87FeUBwzjkHeEBwzjkX5wHB\nOecc4AHBOedcnAcE55xzgAeErHrjDZg7N+hSOOdc1XJqYlou27wZzj0XDjwQiotBJOgSOefctryG\nkCWzZsH69TB9Orz7btClcc657XlAyJKiIvu5xx5wzz3BlsU556riASFLYjHo2BGGD4c334TZs4Mu\nkXPObcsDQhaoWg3hqKPg6quhWTO4996gS+Wcc9tKKSCIyMkiMl9ESkVkZBWPHysi00WkXETO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Ow96Xgvt8iEg74FogoqqHAA2B8ymsz8ZTwMmV\ntlX3WTgF6Bq/DQYeTlchPCBkiKp+parT47+vw/7Z2wH9gafjuz0NnBVMCbNPRNoDpwGPx+8LcDzw\n1/guBfN+iEhz4FjgCQBV3aSqayjcz0cjYGcRaQTsAnxFAX02VPV/ge8qba7us9AfmKzmI2APEWmb\njnJ4QMgCEekEHA58DOylql+BBQ1gz+BKlnXjgBuAivj9VsAaVS2P3y/DgmYh6AKsBv4Yb0J7XESa\nUYCfD1VdDtwLLMUCwQ9ACYX72Uio7rPQDliWtF/a3hsPCBkmIrsCLwHXqeraoMsTFBE5HVilqiXJ\nm6vYtVCGvTUCegEPq+rhwHoKoHmoKvG28f5AZ2AfoBnWLFJZoXw2apKx/xsPCBkkIo2xYPCMqv4t\nvnllonoX/7kqqPJl2VHAmSKyGHgeaw4Yh1V3G8X3aQ+sCKZ4WVcGlKnqx/H7f8UCRCF+Pv4P8KWq\nrlbVzcDfgH4U7mcjobrPQhnQIWm/tL03HhAyJN4+/gTwmaren/TQFODS+O+XAq9ku2xBUNWbVLW9\nqnbCOgzfUdWLgHeBc+K7FdL78TWwTEQOjG86AZhHYX4+lgJ9RGSX+P9N4r0oyM9Gkuo+C1OAS+Kj\njfoAPySalurLJ6ZliIgcDbwPzGFrm/l/Y/0ILwL7Yv8I56pq5c6kvCYixwHDVfV0EemC1RhaAjOA\ni1V1Y5DlyxYR6Yl1sDcBvgAGYhdpBff5EJHRwK+w0XkzgEFYu3hBfDZE5DngOCyr6UrgNuBlqvgs\nxIPmBGxU0gZgoKoWp6UcHhCcc86BNxk555yL84DgnHMO8IDgnHMuzgOCc845wAOCc865OA8Izjnn\nAA8Izjnn4jwgOOecA+D/Aaa8I96AsqQXAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10d99e110>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 绘制不同聚类数目的模型的性能，找到最佳模型／参数（分数最高）\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "plt.plot(Ks, np.array(CH_scores), 'b-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
